package xiegd.com.springbootuse.demo.delay;

import lombok.Builder;
import lombok.Data;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @Author: xieguangda
 * @Description:
 * @Date: 2023/9/8 14:06
 */
@Data
@Builder
public class CancelSendOrderDelay implements Delayed {
    private Integer id;

    private Long timeOut;

    @Override
    public long getDelay(TimeUnit unit) {
        //System.out.println("CancelSendOrderDelay.getDelay啊啊啊：" + unit.convert((timeOut - System.currentTimeMillis()), TimeUnit.MILLISECONDS));
        return unit.convert((timeOut - System.currentTimeMillis()), TimeUnit.MILLISECONDS);
    }


    @Override
    public int compareTo(Delayed other) {
        if (other == this) {
            return 0;
        }
        CancelSendOrderDelay t = (CancelSendOrderDelay) other;
        long d = (getDelay(TimeUnit.MILLISECONDS) - t.getDelay(TimeUnit.MILLISECONDS));
        //System.out.println("CancelSendOrderDelay.compareTo啊啊啊：" + d);
        return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
    }
}
